package com.powernode.controller;

import com.powernode.pojo.User;
import com.powernode.service.impl.UserServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 繁寂
 * @version 1.0
 * @since 1.0
 */
@CrossOrigin
@RestController
@RequestMapping("/book")
public class UserController {

    @Autowired
    private UserServiceImpl userServiceImpl;

    @GetMapping("/userAll")
    public List<User> selectUserAll(){
        return userServiceImpl.selectUserAll();
    }

    @GetMapping("/User/{id}")
    @ResponseBody
    public List<User> selectUser(@Param("id") User user){
        return userServiceImpl.selectUser(user);
    }

    @PostMapping("/insUser")
    public String  insertUser(@RequestBody User user){
        Integer count = userServiceImpl.insertUser(user);
        if(count ==  1){
            return "增加成功";
        }else{
            return "增加失败";
        }
    }

    @PostMapping("/updUser")
    public String updateUser(@RequestBody User user){
        Integer count = userServiceImpl.updateUser(user);
        if(count ==  1){
            return "更改成功";
        }else{
            return "更改失败";
        }
    }

    @PostMapping("/delUser")
    public String deleteUser(@RequestBody User user){
        Integer count = userServiceImpl.deleteUser(user);
        if(count ==  1){
            return "删除成功";
        }else{
            return "删除失败";
        }
    }
}
